package com.neusoft.exception;

import com.neusoft.domain.Result;
import com.neusoft.domain.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*@ControllerAdvice*/
@RestControllerAdvice //表明全局异常处理 并返回json
public class GlobalExceptionAdvice {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        e.printStackTrace();
        return Result.fail(ResultCode.UNKNOWN_ERROR,"服务器异常");
    }
    @ExceptionHandler(BusinessException.class)
    public Result handleBusinessException(BusinessException e){
        e.printStackTrace();
        return Result.fail(e.getCode(),e.getMessage());
    }
}
